<?php
namespace app\api\model;

use think\Model;

class Address extends Base
{
    protected $table = 'user_address';
    protected $autoWriteTimestamp = 'datetime';

    public function lists($token)
    {

        $user = $this->token($token);

        $address = $this->all(['user_id'=>$user->user_id]);

        return $address;

    }

    public function add($token,$data)
    {
        $user = $this->token($token);

        $address = $this->where('user_id',$user->user_id);

        if ($address->count() == 1){

            return false;
        }


        $data['user_id'] = $user->user_id;


        if ($this->create($data)){

            return true;
        }

        return false;
    }

    public function getDetail($id)
    {
        $addr = $this->where('id',$id)->select();

        if ($addr){

            return $addr;
        }

        return false;



    }

}